/*  1:   */ package org.intellij.lang.regexp.surroundWith;
/*  2:   */ 
/*  3:   */

import com.intellij.lang.surroundWith.SurroundDescriptor;
import com.intellij.lang.surroundWith.Surrounder;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import org.intellij.lang.regexp.psi.RegExpAtom;
import org.intellij.lang.regexp.psi.RegExpBranch;
import org.intellij.lang.regexp.psi.RegExpElement;
import org.intellij.lang.regexp.psi.RegExpPattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */
/* 16:   */
/* 17:   */
/* 18:   */
/* 19:   */ 
/* 20:   */ public class SimpleSurroundDescriptor
/* 21:   */   implements SurroundDescriptor
/* 22:   */ {
/* 23:35 */   private static final Surrounder[] a = { new GroupSurrounder("Capturing Group (pattern)", "("), new GroupSurrounder("Non-Capturing Group (?:pattern)", "(?:") };
/* 24:   */   
/* 25:   */   @NotNull
/* 26:   */   public PsiElement[] getElementsToSurround(PsiFile paramPsiFile, int paramInt1, int paramInt2)
/* 27:   */   {
/* 28:42 */     PsiElement[] tmp7_4 = a(paramPsiFile, paramInt1, paramInt2);
/* 29:42 */     if (tmp7_4 == null) {
/* 30:42 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/lang/regexp/surroundWith/SimpleSurroundDescriptor", "getElementsToSurround" }));
/* 31:   */     }
/* 32:42 */     return tmp7_4;
/* 33:   */   }
/* 34:   */   
/* 35:   */   @NotNull
/* 36:   */   public Surrounder[] getSurrounders()
/* 37:   */   {
/* 38:47 */     Surrounder[] tmp3_0 = a;
/* 39:47 */     if (tmp3_0 == null) {
/* 40:47 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/lang/regexp/surroundWith/SimpleSurroundDescriptor", "getSurrounders" }));
/* 41:   */     }
/* 42:47 */     return tmp3_0;
/* 43:   */   }
/* 44:   */   
/* 45:   */   public boolean isExclusive()
/* 46:   */   {
/* 47:52 */     return false;
/* 48:   */   }
/* 49:   */   
/* 50:   */   private PsiElement[] a(PsiFile paramPsiFile, int paramInt1, int paramInt2)
/* 51:   */   {
/* 52:57 */     PsiElement localPsiElement1 = paramPsiFile.findElementAt(paramInt1);
/* 53:58 */     PsiElement localPsiElement2 = paramPsiFile.findElementAt(paramInt2 - 1);
/* 54:59 */     if ((localPsiElement1 instanceof PsiWhiteSpace)) {
/* 55:60 */       paramInt1 = localPsiElement1.getTextRange().getEndOffset();
/* 56:   */     }
/* 57:62 */     if ((localPsiElement2 instanceof PsiWhiteSpace)) {
/* 58:63 */       paramInt2 = localPsiElement2.getTextRange().getStartOffset();
/* 59:   */     }
/* 60:66 */     RegExpElement localRegExpElement1 = a(paramPsiFile, paramInt1, paramInt2, RegExpPattern.class);
/* 61:67 */     if (localRegExpElement1 != null) {
/* 62:67 */       return new RegExpElement[] { localRegExpElement1 };
/* 63:   */     }
/* 64:69 */     RegExpElement localRegExpElement2 = a(paramPsiFile, paramInt1, paramInt2, RegExpBranch.class);
/* 65:70 */     if (localRegExpElement2 != null) {
/* 66:70 */       return new RegExpElement[] { localRegExpElement2 };
/* 67:   */     }
/* 68:72 */     ArrayList localArrayList = new ArrayList();
/* 69:73 */     for (RegExpAtom localRegExpAtom = (RegExpAtom)PsiTreeUtil.findElementOfClassAtRange(paramPsiFile, paramInt1, paramInt2, RegExpAtom.class); localRegExpAtom != null; localRegExpAtom = (RegExpAtom)PsiTreeUtil.findElementOfClassAtRange(paramPsiFile, paramInt1, paramInt2, RegExpAtom.class))
/* 70:   */     {
/* 71:75 */       localArrayList.add(localRegExpAtom);
/* 72:76 */       paramInt1 = localRegExpAtom.getTextRange().getEndOffset();
/* 73:79 */       if (((localPsiElement1 = paramPsiFile.findElementAt(paramInt1)) instanceof PsiWhiteSpace))
/* 74:   */       {
/* 75:80 */         paramInt1 = localPsiElement1.getTextRange().getEndOffset();
/* 76:81 */         localArrayList.add(localPsiElement1);
/* 77:   */       }
/* 78:   */     }
/* 79:85 */     if ((paramInt1 == paramInt2) && (localArrayList.size() > 0))
/* 80:   */     {
/* 81:86 */       PsiElement[] arrayOfPsiElement = PsiUtilCore.toPsiElementArray(localArrayList);
/* 82:87 */       if ((localArrayList.size() == 1) || (PsiTreeUtil.findCommonParent(arrayOfPsiElement) == arrayOfPsiElement[0].getParent())) {
/* 83:88 */         return arrayOfPsiElement;
/* 84:   */       }
/* 85:   */     }
/* 86:91 */     return PsiElement.EMPTY_ARRAY;
/* 87:   */   }
/* 88:   */   
/* 89:   */   @Nullable
/* 90:   */   private static <T extends RegExpElement> T a(PsiFile paramPsiFile, int paramInt1, int paramInt2, Class<T> paramClass)
/* 91:   */   {
/* 92:96 */     RegExpElement localRegExpElement = (RegExpElement)PsiTreeUtil.findElementOfClassAtRange(paramPsiFile, paramInt1, paramInt2, paramClass);
/* 93:97 */     if ((localRegExpElement == null) || (localRegExpElement.getTextRange().getEndOffset() < paramInt2)) {
/* 94:97 */       return null;
/* 95:   */     }
/* 96:98 */     return localRegExpElement;
/* 97:   */   }
/* 98:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.lang.regexp.surroundWith.SimpleSurroundDescriptor

 * JD-Core Version:    0.7.0.1

 */